package com.yxq.mdt.app.modules.personal.presenter;

import com.orhanobut.hawk.Hawk;
import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.constant.SPKey;
import com.yxq.mdt.app.modules.auction.bean.SendGoodsNum;
import com.yxq.mdt.app.modules.login.bean.UserBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonTokenBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonalImNumber;
import com.yxq.mdt.app.modules.personal.bean.MainSaveAddImNumber;
import com.yxq.mdt.app.modules.personal.bean.MyPersonalBean;
import com.yxq.mdt.app.modules.personal.bean.RechargeRecordBean;
import com.yxq.mdt.app.modules.personal.model.MainPersonalModel;
import com.yxq.mdt.app.net.ApiModel;

public class MainPersonalPresenter extends BasePresenter<IMainPersonalContract.View, MainPersonalModel> implements IMainPersonalContract.Presenter {
    /**
     * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认)
     *
     * @param rootView
     * @param model
     */


    public MainPersonalPresenter(IMainPersonalContract.View rootView, MainPersonalModel model) {
        super(rootView, model);
    }

    public void getPersonTokeData() {
        UserBean userBean = Hawk.get(SPKey.SP_KEY_USER_INFO);
        mBaseModel.getTokenData(String.valueOf(userBean.getUserId()), new ApiModel.CommonCallback<MainPersonTokenBean>() {
            @Override
            public void onSuccess(MainPersonTokenBean mainPersonTokenBean) {
                mRootView.onLoadPersonalTokenSuccess(mainPersonTokenBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadPersonalTokenFailed();
            }
        });
    }

    @Override
    public void getOnLoadImNumber() {
        mBaseModel.getImNumberData(new ApiModel.CommonCallback<MainPersonalImNumber>() {
            @Override
            public void onSuccess(MainPersonalImNumber mainPersonalImNumber) {
                mRootView.onLoadImNumberSuccess(mainPersonalImNumber);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadImNumberFailed();
            }
        });
    }

    public void saveIMUserInfo(String nickName) {

        mBaseModel.getImNumber(nickName, new ApiModel.CommonCallback<MainPersonalImNumber>() {
            @Override
            public void onSuccess(MainPersonalImNumber mainPersonTokenBean) {
                mRootView.onLoadAddSaveSuccess(mainPersonTokenBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadAddSaveFailed();
            }
        });
    }

    @Override
    public void getPersonalMyData() {
        MainPersonTokenBean mainPersonTokenBean = Hawk.get(SPKey.SP_KEY_USER_INFO_TOKEN);
        mBaseModel.getPersonalDate(mainPersonTokenBean != null ? mainPersonTokenBean.getToken() : "", new ApiModel.CommonCallback<MyPersonalBean>() {
            @Override
            public void onSuccess(MyPersonalBean myPersonalBean) {
                mRootView.onLoadSuccess(myPersonalBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadPersonalDataFailed();
            }
        });
    }

    public void selectByPageList(String orderByClause, int pageNum, int pageSize) {

        mBaseModel.selectByPageList(orderByClause, pageNum, pageSize, new ApiModel.CommonCallback<RechargeRecordBean>() {
            @Override
            public void onSuccess(RechargeRecordBean rechargeRecordBean) {
                mRootView.onGsGiveSuccess(rechargeRecordBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onGsGiveFailed();
            }
        });
    }

    public void selectEarningsByPageList(String orderByClause, int pageNum, int pageSize) {

        mBaseModel.selectEarningsByPageList(orderByClause, pageNum, pageSize, new ApiModel.CommonCallback<RechargeRecordBean>() {
            @Override
            public void onSuccess(RechargeRecordBean rechargeRecordBean) {
                mRootView.onGsGiveSuccess(rechargeRecordBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onGsGiveFailed();
            }
        });
    }

    public void selectByOrderSendGoodsNum() {
        mBaseModel.selectByOrderSendGoodsNum(new ApiModel.CommonCallback<SendGoodsNum>() {
            @Override
            public void onSuccess(SendGoodsNum rechargeRecordBean) {
                mRootView.inSelectByOrderSendGoodsNumSuccess(rechargeRecordBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.inSelectByOrderSendGoodsNumFailed();
            }
        });
    }
}
